package no.eirikb.bomberman.client;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import no.eirikb.bomberman.applet.Bomberman;
import no.eirikb.bomberman.applet.game.GamePanel;
import no.eirikb.bomberman.applet.GameWaitPanel;
import no.eirikb.bomberman.applet.chat.ChatContainerPanel;
import no.eirikb.bomberman.applet.menu.GamelistPanel;
import no.eirikb.bomberman.applet.menu.MenuPanel;
import no.eirikb.bomberman.shared.Game;
import no.eirikb.bomberman.applet.game.Pos;
import no.eirikb.bomberman.shared.User;
import no.eirikb.bomberman.applet.game.Way;
import no.eirikb.bomberman.shared.clientcommand.ClientEvent;
import no.eirikb.bomberman.shared.message.Message;

/**
 *
 * @author eirikb
 */
public class BombermanClient extends UnicastRemoteObject implements Client, Serializable {

    private Bomberman bomberman;
    private ChatContainerPanel chat;
    private MenuPanel menuPanel;
    private GamePanel gamePanel;
    private GamelistPanel gameListPanel;
    private GameWaitPanel gameWaitPanel;

    public BombermanClient() throws RemoteException {
    }

    public BombermanClient(Bomberman bomberman) throws RemoteException {
        this.bomberman = bomberman;
    }

    public void setMenuPanel(MenuPanel menuPanel) {
        this.menuPanel = menuPanel;
    }

    public void setChat(ChatContainerPanel chat) {
        this.chat = chat;
    }

    public void setGamePanel(GamePanel gamePanel) {
        this.gamePanel = gamePanel;
    }

    public void setGameListPanel(GamelistPanel gameListPanel) {
        this.gameListPanel = gameListPanel;
    }

    public void setGameWaitPanel(GameWaitPanel gameWaitPanel) {
        this.gameWaitPanel = gameWaitPanel;
    }
    // Implemented methods ***************************************************
    public void startGame(Game game) throws RemoteException {
        System.out.println("startgame");
        gamePanel.start(game);
        if (bomberman != null) {
            bomberman.show("game");
        }
    }

    public void ping() throws RemoteException {
    }

    public void chat(Message message) throws RemoteException {
        if (chat != null) {
            chat.chat(message);
        }
    }

    public void addGame(Game game) throws RemoteException {
        System.out.println("addgame");
        if (gameListPanel != null) {
            gameListPanel.addGame(game);
        }
    }

    public void removeGame(Game game) throws RemoteException {
        System.out.println("removegtame");
        gameListPanel.removeGame(game);
    }

    public void updateGame(Game game) throws RemoteException {
        System.out.println("updategame");
        if (gameWaitPanel != null) {
            System.out.println("UpdateLOL!");
            gameWaitPanel.updateGame(game);
        }
    }

    public void clientEvent(ClientEvent event) throws RemoteException {
        gamePanel.clientEvent(event);
    }
}
